package com.siwei.mes.controller.erp;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.entity.erp.Itemorder;
import com.siwei.mes.mapper.experiment.ExperimentItemorderMapper;
import com.siwei.mes.service.erp.ItemorderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * erp小票相关
 *
 * @author linzi
 * @since 2024-07-29 15:22:24
 */
@Api(value = "")
@RestController
@RequestMapping("erpItemorder")
public class ErpItemorderController {
    @Resource
    private ItemorderService itemorderService;
    @Resource
    private ExperimentItemorderMapper experimentItemorderMapper;

    @ApiOperation(value = "分页获取")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<Itemorder, Itemorder> query) {
        return Json.succ().data(itemorderService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取")
    @GetMapping("loadByItId")
    public Json loadById(@RequestParam("ITID") Integer ItId) {
        return Json.succ().data(itemorderService.loadByItId(ItId));
    }

    @ApiOperation(value = "获取所有")
    @PostMapping("getAll")
    public Json getAll(@RequestBody Itemorder entity) {
        return Json.succ().data(ApiResult.addList(itemorderService.getAll(entity)));
    }

    @ApiOperation(value = "绑定erp小票列表")
    @PostMapping("/bindPage")
    public Json appBindPage(@RequestBody @Validated(PageGroup.class) PageQuery<Itemorder, Itemorder> query) {
        return Json.succ().data(itemorderService.bindPage(query));
    }

    @ApiOperation(value = "根据试验委托id获取相关的小票")
    @GetMapping("selectByExperimentId")
    public Json selectByExperimentId(@RequestParam("experimentId") Long experimentId) {
        return Json.succ().data(ApiResult.addList(experimentItemorderMapper.selectByExperimentId(experimentId)));
    }
}
